let urlParse=function(url){
    if(typeof url!=="string"){
        throw new Error("url must be a string")
    }
    let res={}
    let [head,fi]=url.split("?")
    let hash=""
    let query={}
    let fi=[]
    if(fi){
        fi=fi.split("#")
    }
    if(fi[1]){
        hash="#"+fi[1]
    }
    let temp_query=fi[0].split("&")
    while(temp_query.length){
        let temp=temp_query.pop()
        temp_res=temp.split("=")
        query[temp_res[0]]=temp_res[1]
    }
    res.hash=hash
    res.query=query
    let [protocol,site]=head.split("//")
    let pos=site.indexOf("/")
    let origin=protocol+"//"+site.slice(0,pos)
    pathname=site.slice(pos+1,site.length)?site.slice(pos+1,site.length):""
    res.origin=origin
    res.pathname=pathname
    let port=site.split(":")[1]?site.split(":")[1]:""
    res.port=port
    return res
}
console.log(urlParse("https://www.baodu.com/a/v"))